<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <title>新年活动设置</title>
    <link rel="stylesheet" href="css/vant.css">
    <link rel="stylesheet" href="css/changeShop.css">
</head>

<body>
    <div id="app" v-cloak>
        <div class="inputBox">
            <div>
                <span>虚拟人数</span>
                <input type="text" v-model="xuniNum" placeholder="请输入虚拟人数">
            </div>
            <!-- <div>
                <span>真实人数</span>
                <input type="text" v-model="zhenshiNum" placeholder="请输入真实人数">
            </div> -->
            <div>
                <span>开始集福袋活动时间</span>
                <input type="text" v-model="startTime" readonly @click="showTime(1)" placeholder="请选择开始时间">
            </div>
            <div>
                <span>活动结束时间(不可进行任何操作，未提现的也不可提现)</span>
                <input type="text" v-model="endTime" readonly @click="showTime(2)" placeholder="请选择结束时间">
            </div>
        </div>
        <div class="infoBox">
            <div>虚拟人数：<span>{{xuNiNum}}</span> </div>
            <div>真实人数：<span>{{realNum}}</span></div>
            <div>总人数：<span>{{totalNum}}</span> </div>
        </div>

        <div class="btnBox" @click="submitHandle">
            <div>提交</div>
        </div>

    

        <div class="setBox">
            <span>论坛页面集福袋入口展示开关</span>
            <van-switch v-model="fuActiveFlag" @change="changeActive(1)" />
        </div>
        <!-- <div class="setBox">
            <span>论坛页面充值活动入口展示开关</span>
            <van-switch v-model="cActiveFlag" @change="changeActive(2)" />
        </div> -->

        <div class="loading" v-if="isShow">
            <img src="./img/load.gif" alt="">
        </div>

        <van-popup v-model="show" position="bottom">
            <van-datetime-picker v-model="currentDate" type="datetime" title="选择活动时间" :min-date="minDate"
                :max-date="maxDate" @confirm="confirmHandle" @cancel="cancelHandle" />
        </van-popup>

    </div>
    <script src="js/vue.min.js"></script>
    <script src="js/flex_ible/lib-flexible.js"></script>
    <script src="js/vue-lazyload.js"></script>
    <script src="js/vant.min.js"></script>
    <script src="js/vue-lazyload.js"></script>
    <script src="js/url.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/ajax.js"></script>
    <script type="text/javascript" src="http://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script>
        Vue.use(VueLazyload);
        var vm = new Vue({
            el: "#app",
            data: {
                activeFlag: true,
                isShow: false,
                xuniNum: 0,
                startTime: '',
                endTime: '',
                minDate: new Date(2024, 0, 19),
                maxDate: new Date(2028, 2, 1),
                currentDate: new Date(),
                show: false,
                timeFlag: -1,
                xuNiNum: 0,
                realNum: 0,
                totalNum: 0,
                fuActiveFlag: false,
                cActiveFlag: false,
            },
            created() {
                this.getIndexList()
            },
            methods: {
                confirmHandle() {
                    console.log(this.currentDate);
                    var year = this.currentDate.getFullYear(); // 获取年份
                    var month = this.currentDate.getMonth() + 1; // 获取月份（注意月份是从0开始计数的，所以要加1）
                    var day = this.currentDate.getDate(); // 获取日期
                    var h = this.currentDate.getHours(); // 获取日期
                    var m = this.currentDate.getMinutes(); // 获取日期
                    month = month < 10 ? '0' + month : month
                    day = day < 10 ? '0' + day : day
                    h = h < 10 ? '0' + h : h
                    m = m < 10 ? '0' + m : m

                    var formattedTime = year + "-" + month + "-" + day + ' ' + h + ':' + m + ':00'; // 拼接年月日
                    console.log(formattedTime);
                    if (this.timeFlag == 1) {
                        this.startTime = formattedTime
                    } else {
                        this.endTime = formattedTime
                    }
                    this.cancelHandle()
                },
                cancelHandle() {
                    this.show = false
                },
                showTime(flag) {
                    this.timeFlag = flag
                    console.log(flag);
                    this.show = true
                },
                submitHandle() {
                    console.log(this.xuniNum);
                    console.log(this.zhenshiNum);
                    console.log(this.startTime);
                    console.log(this.endTime);
                    var that = this;
                    that.isShow = true
                    ajax({
                        type: "post",
                        url: newUrl + "jifu/setJifuCondition",
                        data: {
                            xuniNum: that.xuniNum,
                            zhenshiNum: 0,
                            startTime: that.startTime,
                            endTime: that.endTime,
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            var res = JSON.parse(res)
                            if (res.flag) {
                                alert('操作成功')
                            } else {
                                alert('操作失败，请重试')
                            }
                            that.isShow = false
                            that.xuNiNum += that.xuniNum * 1
                            that.totalNum += that.xuniNum * 1
                        },
                    })
                },
                getIndexList: function () {
                    var _this = this;
                    _this.isShow = true
                    ajax({
                        url: newUrl + 'jifu/getJifuCondition',
                        type: 'post',
                        data: {},
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            var res = JSON.parse(res);
                            if (res.flag) {
                                console.log(res.data.jifuNumbers);
                                _this.isShow = false
                                _this.xuNiNum = res.data.jifuNumbers[0].xuNum
                                _this.realNum = res.data.jifuNumbers[0].num
                                _this.totalNum = _this.xuNiNum + _this.realNum
                                _this.startTime = res.data.jifuNumbers[0].startTime
                                _this.endTime = res.data.jifuNumbers[0].endTime

                                _this.fuActiveFlag = false
                                _this.cActiveFlag = false
                                // 1 开始  0 结束
                                _this.fuActiveFlag = res.data.activitySwitch.shopId == 1
                                _this.cActiveFlag = res.data.activitySwitch.shopId == 2

                            }
                        }
                    })
                },

                changeActive(flag) {
                    var status = 0
                    if (flag == 1 && this.fuActiveFlag) {
                        status = 1
                        this.cActiveFlag = false
                    } else if (flag == 2 && this.cActiveFlag) {
                        status = 2
                        this.fuActiveFlag = false
                    }

                    console.log(this.activeFlag);
                    var that = this;
                    that.isShow = true
                    ajax({
                        type: "post",
                        url: newUrl + "jifu/setJifuStart",
                        data: {
                            start: status
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            var res = JSON.parse(res)
                            if (res.flag) {
                                alert('操作成功')
                            } else {
                                alert('操作失败，请重试')
                            }
                            that.isShow = false
                        },
                    })
                },
            }
        })
    </script>

</body>

</html>